
import 'package:flutter/cupertino.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:massagist/manager/file_manager.dart';
import 'package:massagist/pages/phone_auto_page.dart';
import 'package:massagist/pages/web_page.dart';
import 'package:massagist/views/mass_appbar.dart';
import 'package:shared_preferences/shared_preferences.dart';

import '../generated/l10n.dart';
import '../manager/config.dart';

class PrivacyPage extends StatefulWidget {
  @override
  State<PrivacyPage> createState() => PrivacyPageState();
}

class PrivacyPageState extends State<PrivacyPage> {
  String privacyStr = "";
  @override
  void initState() {
    // TODO: implement initState
    super.initState();

    readInfo();
  }

  Future<void> readInfo() async {
    privacyStr = await FileManager.readPrivacy();
    setState(() {

    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      // appBar: MassAppbar(title: S.current.SERVICE_PRIVACY, backIocn: Icons.close,),
      body: Container(
        padding: EdgeInsets.only(left: 16.sp, top: 30.sp, right: 16.sp),
        child: Column(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: [
            Container(
              child: RichText(
                text: TextSpan(
                  style: TextStyle(
                    fontSize: 12.sp,
                    color: Color(0xFF999999),
                  ),
                  children: [
                    TextSpan(text: S.current.PRIVACY_TEXT_1, style: TextStyle(color: Color(0xFF333333), fontSize: 14.sp)),
                    TextSpan(text: S.current.PRIVACY_TEXT_2, style: TextStyle(color: Color(0xFF00CA7E), fontSize: 14.sp),
                      recognizer: TapGestureRecognizer()..onTap = () {
                        Navigator.push(context, MaterialPageRoute(builder: (context) => WebPage(path: PRIVACY_ARGEEMENT)));
                      }
                    ),
                    TextSpan(text: S.current.PRIVACY_TEXT_3, style: TextStyle(color: Color(0xFF333333), fontSize: 14.sp)),
                    TextSpan(text: S.current.PRIVACY_TEXT_4, style: TextStyle(color: Color(0xFF00CA7E), fontSize: 14.sp),
                        recognizer: TapGestureRecognizer()..onTap = () {
                          Navigator.push(context, MaterialPageRoute(builder: (context) => WebPage(path: USER_AGREEMENT)));
                        }),
                    TextSpan(text: S.current.PRIVACY_TEXT_5, style: TextStyle(color: Color(0xFF333333), fontSize: 14.sp)),
                    // TextSpan(
                    //     text: S.current.LOGIN_RIGHT_PRIVACY,
                    //     style: TextStyle(
                    //       color: Color(0xFF00CA7E),
                    //     ),
                    //     recognizer: TapGestureRecognizer()..onTap = () {
                    //
                    //     }
                    // )
                  ],
                ),
              ),
            ),
            Container(
              margin: EdgeInsets.only(bottom: 50.sp),
              child: Column(
                children: [

                  GestureDetector(
                    child: Container(
                      width: double.infinity,
                      height: 44.sp,
                      decoration: BoxDecoration(
                        color: Color(0xFF00CA7E),
                        borderRadius: BorderRadius.circular(22.sp), // 设置圆角半径
                      ),
                      child: Center(
                        child: Text(
                          S.current.PRIVACY_AGREE,
                          style: TextStyle(color: Colors.white, fontSize: 16.sp),
                        ),
                      ),
                    ),
                    onTap: () async {
                      SharedPreferences prefs = await SharedPreferences.getInstance();
                      prefs.setBool("is_first", false);

                      Navigator.pushAndRemoveUntil(
                        context,
                        MaterialPageRoute(builder: (context) => PhoneAutoPage()),
                            (route) => false,
                      );
                    },
                  ),
                  GestureDetector(
                    child: Container(
                      margin: EdgeInsets.only(top: 20.sp),
                      child: Text(S.current.PRIVACY_REFUSE, style: TextStyle(
                        color: Color(0xFF333333),
                        fontSize: 16.sp,
                      )),
                    ),
                    onTap: () {
                      SystemNavigator.pop();
                    },
                  )
                ],
              ),
            )
          ],
        ),
      ),
    );
  }
}